// pages/repair/repair.js
const httprequest = require('../../utils/http_utils.js')
const dateTimePicker = require('../../utils/dateTimePicker.js')
const common = require('../../utils/common.js')
const dateutil = require('../../utils/date_util.js')
const app = getApp();
var focus = 0; //用来判断是否清空输入框
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isyulan: false, //是否是预览状态
    error: '', //错误提示
    success: '',
    locationitems: [{
        name: '公共区域',
        value: 1
      },
      {
        name: '商铺',
        value: 2
      },
    ], //公共区域/商铺
    chargeList: [{
        name: '是',
        value: 1
      },
      {
        name: '否',
        value: 0,
        checked: 'true'
      }
    ], //是否收费
    chooseWorkplace: '', //是否选中公区租区
    Ispublic: false, //是否选中公区
    Isrent: false, //是否选中租区
    RegionArray: [{
      RowGuid: '0',
      RegionName: '请选择',
      RegionCode: '00'
    }], //区域
    RegionIndex: 0,
    EquipmentArray: [{ //报修设备集合
      RowGuid: '0',
      Name: '请选择'
    }],
    EquipmentIndex: 0, //报修设备下标
    BuildingArray: [{
      RowGuid: '0',
      BuildingName: '请选择',
      BuildingCode: '00'
    }], //建筑
    BuildingIndex: 0,
    FloorArray: [{
      RowGuid: '0',
      FloorName: '请选择',
      FloorCode: '00'
    }], //楼层
    FloorIndex: 0,
    RegionGuid: '',
    BuildingGuid: '',
    FloorGuid: '',
    RoomGuid: '',
    picnum: 0, //已上传图片数量
    imgs: [], //选择图片地址
    RoomArray: [{
      RowGuid: '0',
      Room: '请选择'
    }], //房间
    RoomIndex: 0,
    BusinessIndex: 0,
    FailureArray: [], //故障类型
    FaileTypeIndex: 0, //故障类型第一列
    FaileTypeIndex1: 0, //故障类型第二列
    FailureTypeGuid: '', //故障类型guid
    RoomInfo: [], //所在房间选择返回值
    showyulan: true, //是否显示预览
    showsubmit: false, //是否显示提交
    room: '请选择', //所在房间
    roomOnlyGuid: '', //所在房间的Guid
    WorkTime: '', //预约时间
    WorkPlace: [
      [],
      [],
      [],
      [],
    ], //区域建筑楼层房间
    RepairPerson: '', //报修人
    RepairPersonTel: '', //联系方式
    RepairTime: '',
    WorkType: '3',
    WorkOrderState: '6',
    FailureType: '请选择', //故障类型
    Description: '请输入详情描述！',
    BusinessGuid: '',
    RegisterGuid: '', //window.localStorage.RowGuid,
    IsPublicRent: '',
    ComplateTime: '请选择', //最后时限
    WorkPlaceRoomNames: '',
    LeaderGuid_B: '', //值班人员guid
    LeaderName_B: '查看', //值班人员
    FileGuid: [],
    //时间选择器
    dateTimeArray: null,
    dateTime: null,
    startYear: 2000,
    endYear: 2050,
    title: '报修', //导航栏名称
    //故障类型选择器
    Failure_Type: '请选择', //故障类型显示值
    FailTypeArray: [
      [],
      [],
      []
    ], //故障类型选择器
    FailTypeIndex: [0, 0, 0],
    table_fail: [], //故障类型table
    progress: '',
    paddingbottom_height: 250,
    imgs2: [], //用于过渡图片地址和rowguid关系
    isCharge: 0, // 是否收费
    EquipmentObtainGuid: '', //空间Guid
    EquipGuid: '', //设备Guid
    showModal:false,  //遮罩
    dataList:[], //值班人员
    customHeight: 0, //自定义高度
  },

  WorkPlaceChange: function(e) {
    console.log(e.detail.value)
    this.setData({
      chooseWorkplace: e.detail.value
    })
    if (e.detail.value == '公共区域') {
      this.setData({
        Ispublic: true,
        Isrent: false,
        IsPublicRent: '1',
        WorkPlaceRoomNames: '',
        ComplateTime: '请选择',
        Failure_Type: '请选择',
        FailTypeIndex: '',
        ComplateTime: '请选择',
        FaileTypeIndex: 0,
        FaileTypeIndex1: 0,
      })
      this.getRegion();
    } else if (e.detail.value == '商铺') {
      this.setData({
        Isrent: true,
        Ispublic: false,
        IsPublicRent: '0',
        WorkPlace: [],
        ComplateTime: '请选择',
        Failure_Type: '请选择',
        FailTypeIndex: '',
        ComplateTime: '请选择',
        FaileTypeIndex: 0,
        FaileTypeIndex1: 0,
      })
    }
  },

  //是否收费赋值
  charge: function(e) {
    this.setData({
      isCharge: e.detail.value
    })
    console.log(this.data.isCharge)
  },

  bindTimeChange: function(e) {
    this.setData({
      WorkTime: e.detail.value
    })
  },

  bindpersoninput: function(e) {
    this.setData({
      RepairPerson: e.detail.value
    })
  },

  bindmobileinput: function(e) {
    this.setData({
      RepairPersonTel: e.detail.value
    })
  },

  bindRegionChange: function(e) {
    console.log(e.detail.value+"------------区域")
    this.setData({
      RegionGuid: this.data.RegionArray[e.detail.value].RowGuid,
      RegionIndex: e.detail.value
    })
    var newarray = this.data.WorkPlace
    if (this.data.RegionArray[e.detail.value].RowGuid != '') {
      this.getBuilding();
      // newarray.push(this.data.RegionArray[e.detail.value].RowGuid)
      newarray[0] = this.data.RegionArray[e.detail.value].RowGuid;
      newarray[1] = '';
      newarray[2] = '';
      newarray[3] = '';
    } else {
      this.setData({
        RegionGuid: '',
        RegionIndex: 0,
      })
      newarray[0] = '';
      newarray[1] = '';
      newarray[2] = '';
      newarray[3] = '';
    }
    this.setData({
      BuildingGuid: '',
      BuildingIndex: 0,
      FloorGuid: '',
      FloorIndex: 0,
      RoomIndex: 0,
      WorkPlaceRoomNames: '',
      WorkPlace: newarray
    })
    console.log('111', this.data.WorkPlace)
  },

  bindBuildingChange: function(e) {
    console.log(e.detail.value)
    this.setData({
      BuildingGuid: this.data.BuildingArray[e.detail.value].RowGuid,
      BuildingIndex: e.detail.value
    })
    var newarray = this.data.WorkPlace
    if (this.data.BuildingArray[e.detail.value].RowGuid != '') {
      this.getFloor();
      //newarray.push(this.data.BuildingArray[e.detail.value].RowGuid)
      newarray[1] = this.data.BuildingArray[e.detail.value].RowGuid;
    } else {
      this.setData({
        BuildingGuid: '',
        BuildingIndex: 0,
      })
      newarray[1] = '';
      newarray[2] = '';
      newarray[3] = '';
    }
    this.setData({
      FloorGuid: '',
      FloorIndex: 0,
      RoomIndex: 0,
      WorkPlaceRoomNames: '',
      WorkPlace: newarray
    })
    console.log('222', this.data.WorkPlace)
  },

  bindFloorChange: function(e) {
    console.log(e.detail.value)
    this.setData({
      FloorGuid: this.data.FloorArray[e.detail.value].RowGuid,
      FloorIndex: e.detail.value
    })
    var newarray = this.data.WorkPlace
    if (this.data.FloorArray[e.detail.value].RowGuid != '') {
      console.log(this.data.FloorArray[e.detail.value].RowGuid + '-----')
      this.getRoom();
      //newarray.push(this.data.FloorArray[e.detail.value].RowGuid)
      newarray[2] = this.data.FloorArray[e.detail.value].RowGuid;
    } else {
      this.setData({
        FloorGuid: '',
        FloorIndex: 0,
      })
      newarray[2] = '';
      newarray[3] = '';
    }
    this.setData({
      RoomIndex: 0,
      WorkPlaceRoomNames: '',
      WorkPlace: newarray
    })
    console.log('333', this.data.WorkPlace)
  },

  bindRoomChange: function(e) {
    console.log(e.detail.value)
    console.log(this.data.RoomArray)
    this.setData({
      RoomIndex: e.detail.value,
      WorkPlaceRoomNames: this.data.RoomArray[e.detail.value].Room,
      RoomGuid: this.data.RoomArray[e.detail.value].RowGuid,
      EquipmentObtainGuid: '',
      EquipmentIndex:0
    })
    var newarray = this.data.WorkPlace
    if (this.data.RoomArray[e.detail.value].RowGuid != '') {
      // this.getRoom();
      //newarray.push(this.data.RoomArray[e.detail.value].RowGuid)
      newarray[3] = this.data.RoomArray[e.detail.value].RowGuid;
    } else {
      this.setData({
        RoomIndex: 0,
        WorkPlaceRoomNames: '',
      })
      newarray[3] = '';
    }
    this.setData({
      WorkPlace: newarray
    })
    console.log('444', this.data.WorkPlace)
    this.setData({
      EquipmentObtainGuid: this.data.RoomGuid
    })
    console.log(this.data.EquipmentObtainGuid + "----------当前房间ID")
    this.EquipmentObtain(this.data.EquipmentObtainGuid);
  },

  //获取输入框的值
  textareaChange: function(e) {
    this.setData({
      Description: e.detail.value
    })
  },

  //输入框获取焦点
  textareaFocus: function() {
    
    console.log(focus)
    if (focus == 0 && this.data.Description == '请输入详情描述！'){
      this.setData({
        Description:''
      })
    }
    focus += 1;
  },

  //输入框失去焦点
  textareaBlur: function() {
    if (this.data.Description == '' || this.data.Description == null){
      this.setData({
        Description:"请输入详情描述！"
      })
      focus = 0;
    }
  },

  //选择所在房间
  chooseRoom: function() {
    wx.navigateTo({
      url: '/pages/shopsRoom/shopsRoom',
    })
  },

  bindComplateTimeChange: function(e) {
    this.setData({
      ComplateTime: this.data.ComplateTimeArray[e.detail.value]
    })
    console.log(this.data.ComplateTimeArray[e.detail.value])
  },

  //选择图片
  chooseimage: function() {
    var that = this
    // var fileRowGuid = that.data.FileGuid;
    var newImgs = that.data.imgs
    var imgs_2 = that.data.imgs2
    wx.chooseImage({
      count: 9 - that.data.imgs.length,
      sizeType: ['compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        const tempFilePaths = res.tempFilePaths
        // console.log('选择图片',tempFilePaths)
        for (var i = 0; i < tempFilePaths.length; i++) {
          newImgs.push(tempFilePaths[i])
        }
        // debugger
        for (var i = 0; i < tempFilePaths.length; i++) {
          let path = tempFilePaths[i]
          // console.log('path', path)
          //压缩图片
          wx.compressImage({
            src: path,
            quality: 80,
            success: function(res) {
              console.log(res)
              var tempimgpath = res.tempFilePath
              const uploadFile = wx.uploadFile({
                url: httprequest.host + httprequest.apiInfo.MultipleFileUploadMobileApi,
                filePath: tempimgpath,
                name: dateutil.getNowTime(),
                header: {
                  "Content-Type": "multipart/form-data"
                },
                success: function(res) {
                  // console.log(typeof(res), typeof(res.data))
                  var param1 = {
                    path: path,
                    path2: tempimgpath,
                    RowGuid: JSON.parse(res.data).RowGuid,
                    FileGuid: JSON.parse(res.data).FileGuid
                  }
                  imgs_2.push(param1)
                  // fileRowGuid.push(param)
                  // console.log('fileRowGuid', fileRowGuid)
                },
                fail: function(err) {
                  that.setData({
                    error: '图片上传失败'
                  })
                  console.error(err)
                }
              })
              uploadFile.onProgressUpdate((res) => {
                // console.log("上传进度", res.progress)
                if (res.progress == 100) {
                  wx.hideLoading()
                } else {
                  wx.showLoading({
                    title: '图片已上传' + res.progress + '%',
                  })
                }
              })
            },
            fail: function(err) {
              console.error(('压缩图片失败', err))
            }
          })
        }
        that.setData({
          imgs2: imgs_2,
          imgs: newImgs,
          picnum: that.data.imgs.length,
          // FileGuid: fileRowGuid
        })
        console.log('imgs---', that.data.imgs)
        console.log('imgs_2---', that.data.imgs2)
        if (that.data.picnum >= 5) {
          that.setData({
            paddingbottom_height: 400
          })
        } else {
          that.setData({
            paddingbottom_height: 250
          })
        }
        // console.log('FileGuid', that.data.FileGuid)
      }
    })
  },

  //删除图片
  deleteImg: function(e) {
    var that = this;
    // console.log(e.currentTarget.dataset.index + "___________下标显示")
    wx.showModal({
      title: '删除图片',
      content: '确定删除图片',
      confirmText: '删除',
      success: function(res) {
        if (res.confirm) {
          let index = e.currentTarget.dataset.index;
          let imgs_1 = that.data.imgs;
          let imgs_2 = that.data.imgs2;
          // console.log('删除前的imgs_2', imgs_2)
          let filepath = e.currentTarget.dataset.filepath
          if (that.data.isyulan == false) {
            for (var i = 0; i < imgs_2.length; i++) {
              if (imgs_2[i].path == filepath) {
                // console.log('要删除了啊', filepath)
                // console.log('index=' + index, 'i=' + i)
                var param = {
                  RowGuid: imgs_2[i].RowGuid
                }
                // console.log('删除的RowGuid----', imgs_2[i].RowGuid)
                httprequest.GetValidateRequest(httprequest.apiInfo.MultipleFileDeleteMobileApi, param,
                  function(res) {
                    console.log('删除的结果---', res)
                  },
                  function(err) {
                    console.error(err)
                  })
                imgs_2.splice(i, 1)
              }
            }
            imgs_1.splice(index, 1)
            console.log('删除后的imgs---', imgs_1)
            console.log('删除后的imgs2---', imgs_2)
            that.setData({
              imgs: imgs_1,
              picnum: that.data.imgs.length,
              imgs2: imgs_2
            })
            if (that.data.picnum >= 5) {
              that.setData({
                paddingbottom_height: 400
              })
            } else {
              that.setData({
                paddingbottom_height: 250
              })
            }
          }
        }
      }
    })
  },

  //获取所属区域
  getRegion: function() {
    var that = this
    httprequest.GetValidateRequest(httprequest.apiInfo.Project_GetProjectRegionApi, null,
      function(res) {
        console.log(JSON.stringify(res))
        if (res.length > 0) {
          var newArray = that.data.RegionArray
          for (var i = 0; i < res.length; i++) {
            newArray.push(res[i])
          }
          that.setData({
            RegionArray: newArray
          })
        }
      },
      function(err) {
        console.error(err)
      })
  },

  //获取所属建筑
  getBuilding: function() {
    console.log("建筑-----" + this.data.RegionGuid)
    var that = this
    that.setData({
      BuildingArray: [{
        RowGuid: '',
        BuildingName: '请选择',
        BuildingCode: '00'
      }],
      EquipmentObtainGuid: '',
      EquipmentIndex: 0
    })
    var param = {
      RegionGuid: this.data.RegionGuid
    };
    httprequest.GetValidateRequest(httprequest.apiInfo.Project_GetProjectBuildingApi, param,
      function(res) {
        console.log(JSON.stringify(res))
        if (res.length > 0) {
          var newArray = that.data.BuildingArray
          for (var i = 0; i < res.length; i++) {
            newArray.push(res[i])
          }
          that.setData({
            BuildingArray: newArray
          })
        }
      },
      function(err) {
        console.error(err)
      })
    that.setData({
      EquipmentObtainGuid: that.data.RegionGuid
    })
    that.EquipmentObtain(that.data.EquipmentObtainGuid);
  },

  //获取所属楼层
  getFloor: function() {
    console.log("楼层-----" + this.data.BuildingGuid)
    var that = this
    that.setData({
      FloorArray: [{
        RowGuid: '',
        FloorName: '请选择',
        FloorCode: '00'
      }],
      EquipmentObtainGuid: '',
      EquipmentIndex: 0
    })
    var param = {
      BuildingGuid: that.data.BuildingGuid
    };
    httprequest.GetValidateRequest(httprequest.apiInfo.Project_GetProjectFloorApi, param,
      function(res) {
        console.log(JSON.stringify(res))
        if (res.length > 0) {
          var newArray = that.data.FloorArray
          for (var i = 0; i < res.length; i++) {
            newArray.push(res[i])
          }
          that.setData({
            FloorArray: newArray
          })
        }
      },
      function(err) {
        console.error(err)
      })
    that.setData({
      EquipmentObtainGuid: that.data.BuildingGuid
    })
    that.EquipmentObtain(that.data.EquipmentObtainGuid);
  },

  //获取所属房间
  getRoom: function() {
    console.log("房间-----" + this.data.FloorGuid)
    var that = this
    that.setData({
      RoomArray: [{
        RowGuid: '',
        Room: '请选择'
      }],
      EquipmentObtainGuid: '',
      EquipmentIndex: 0
    })
    var param = {
      FloorGuid: that.data.FloorGuid
    };
    httprequest.GetValidateRequest(httprequest.apiInfo.Project_GetProjectRoomApi, param,
      function(res) {
        console.log(JSON.stringify(res))
        if (res.length > 0) {
          var newArray = that.data.RoomArray
          for (var i = 0; i < res.length; i++) {
            newArray.push(res[i])
          }
          that.setData({
            RoomArray: newArray
          })
        }
      },
      function(err) {
        console.error(err)
      })
    that.setData({
      EquipmentObtainGuid: that.data.FloorGuid
    })
    that.EquipmentObtain(that.data.EquipmentObtainGuid);
  },

  //获取故障类型
  getFailureType: function() {
    var that = this
    var param = {
      "ProjectGuid": "",
      "WorkOrderRowGuid": "",
      "RowGuid": "",
    }
    httprequest.GetValidateRequest(httprequest.apiInfo.GetProjectWyOrdersMobileApi, param,
      function(res) {
        that.setData({
          table_fail: JSON.parse(res.Table1)
        })
        var failtable = JSON.parse(res.Table1)
        var newArr = failtable.filter(function(item) {
          return item.ParentGuid === "0";
        });
        that.setData({
          FailureArray: failtable,
          FaileType: newArr,
        })
        var arr = new Array();
        arr = that.data.FailTypeArray;
        arr[0] = newArr
        that.setData({
          FailTypeArray: arr
        })
        that.changeFailure()
      },
      function(err) {
        console.error(err)
      })
  },

  //预览
  submit_yulan: function() {
    var that = this
    if (that.data.chooseWorkplace == '') {
      that.setData({
        error: '请选择公共区域/商铺'
      })
      return false;
    } else if (that.data.chooseWorkplace == '公共区域') {
      if (that.data.WorkPlace.length == 0) {
        that.setData({
          error: '请选择所属区域'
        })
        return false;
      }
    } else if (that.data.chooseWorkplace == '商铺') {
      if (that.data.WorkPlaceRoomNames.length == 0) {
        that.setData({
          error: '请选择所在房间'
        })
        return false;
      }
    }
    if (that.data.FailureTypeGuid.length == 0) {
      that.setData({
        error: '请选择故障类型'
      })
      return false;
    }  else if (that.data.Description.length == 0) {
      that.setData({
        error: '请填写详情描述'
      })
      return false;
    } else {
      this.setData({
        showyulan: false,
        showsubmit: true,
        isyulan: true
      })
    }
  },

  //取消
  submit_quxiao: function() {
    this.setData({
      showyulan: true,
      showsubmit: false,
      isyulan: false
    })
  },

  //提交
  submit: function() {
    var that = this
    console.log(that.data.WorkPlace)
    console.log(that.data.FailureTypeGuid + "——————————————————————————故障类型")
    // if (that.data.WorkPlaceRoomNames == '请选择') {
    //   that.setData({
    //     WorkPlaceRoomNames: ''
    //   })
    // }
    //必填判断
    // if (that.data.LeaderName_B == '请选择') {
    //   that.setData({
    //     error: '请选择部门主管'
    //   })
    //   return false;
    // }
    if (that.data.chooseWorkplace == '') {
      that.setData({
        error: '请选择公共区域/商铺'
      })
      return false;
    } else if (that.data.chooseWorkplace == '公共区域') {
      if (that.data.WorkPlace.length == 0) {
        that.setData({
          error: '请选择所属区域'
        })
        return false;
      }
    } else if (that.data.chooseWorkplace == '商铺') {
      console.log("=============", that.data.chooseWorkplace)
      if (that.data.WorkPlaceRoomNames.length == 0) {
        that.setData({
          error: '请选择所在房间'
        })
        return false;
      }
    }
    if (that.data.FailureTypeGuid.length == 0) {
      that.setData({
        error: '请选择故障类型'
      })
      return false;
    } else if (that.data.Description.length == 0) {
      that.setData({
        error: '请填写详情描述'
      })
      return false;
    } else {
      var imgs2 = that.data.imgs2
      var temp = that.data.FileGuid
      if (imgs2.length > 0) {
        for (var i = 0; i < imgs2.length; i++) {
          var param1 = {
            RowGuid: imgs2[i].RowGuid,
            FileGuid: imgs2[i].FileGuid
          }
          temp.push(param1)
        }
        that.setData({
          FileGuid: temp
        })
        console.log('FileGuid------', that.data.FileGuid)
      }

      var param = {
        WorkTime: that.data.WorkTime,
        WorkPlace: JSON.stringify(that.data.WorkPlace),
        RepairPerson: that.data.RepairPerson,
        RepairPersonTel: that.data.RepairPersonTel,
        RepairTime: that.data.RepairTime,
        WorkType: that.data.WorkType,
        WorkOrderState: that.data.WorkOrderState,
        FailureType: that.data.FailureTypeGuid,
        Description: that.data.Description,
        BusinessGuid: that.data.BusinessGuid,
        RegisterGuid: wx.getStorageSync('UserInfo').AppLogin.RowGuid,
        IsPublic: that.data.IsPublicRent,
        ComplateTime: that.data.ComplateTime,
        WorkPlaceRoomNames: that.data.WorkPlaceRoomNames,
        LeaderGuid_B: that.data.LeaderGuid_B,
        // LeaderName_B: that.data.LeaderName_B,
        FileGuid: that.data.FileGuid,
        IsCharge: that.data.isCharge,
        EquipGuid: that.data.EquipGuid
      }
      console.log('param------', JSON.stringify(param))
      httprequest.PostValidateRequest(httprequest.apiInfo.AddWorkOrderApi, param,
        function(res) {
          console.log(res)
          if (res == '0') {
            that.setData({
              success: '新增工单成功'
            })
            wx.redirectTo({
              // url: '/pages/workorderlist/workorderlist?currentTab=1&state=6',
              url: '/pages/success/success?type=repair',
            })
          } else {
            that.setData({
              error: '新增工单失败'
            })
          }
        },
        function(err) {
          console.error(err)
          that.setData({
            error: '新增工单失败'
          })
        }
      )
    }
  },

  //选择值班人员
  chooseWatchman: function() {
    var that = this;
    if (that.data.isyulan == false) {
      // wx.navigateTo({
      //   url: '/pages/Watchman/Watchman',
      // })

      that.setData({
        showModal: true,
        isyulan:true
      })
      console.log(that.data.showModal)
      that.setData({
        dataList: []
      })
      var param = {
        strParam: ''
      }
      httprequest.PostValidateRequest(httprequest.apiInfo.GetSchedulingAndUsesNewApi, param, function (data) {
        console.log(JSON.stringify(data) + "___________________返回结果")
        if (data.length > 0) {
          that.setData({
            dataList: data
          })
        }
      }, function (err) {

      })
    }
  },
  ok: function () {
    this.setData({
      showModal: false,
      isyulan: false
    })
  },

  changeDateTime(e) {
    this.setData({
      dateTime: e.detail.value
    });
  },

  changeDateTimeColumn(e) {
    var arr = this.data.dateTime,
      dateArr = this.data.dateTimeArray;
    arr[e.detail.column] = e.detail.value;
    dateArr[2] = dateTimePicker.getMonthDay(dateArr[0][arr[0]], dateArr[1][arr[1]]);
    this.setData({
      dateTimeArray: dateArr,
      dateTime: arr,
      RepairTime: this.data.dateTimeArray[0][this.data.dateTime[0]] + '-' + this.data.dateTimeArray[1][this.data.dateTime[1]] + '-' + this.data.dateTimeArray[2][this.data.dateTime[2]] + ' ' + this.data.dateTimeArray[3][this.data.dateTime[3]] + ':' + this.data.dateTimeArray[4][this.data.dateTime[4]]
    })
  },

  changefail_type: function(e) {
    var index = e.detail.value
    this.setData({
      Failure_Type: this.data.FailTypeArray[0][index[0]].name + '/' + this.data.FailTypeArray[1][index[1]].name + '/' + this.data.FailTypeArray[2][index[2]].name,
      FailureTypeGuid: this.data.FailTypeArray[0][index[0]].RowGuid + ',' + this.data.FailTypeArray[1][index[1]].RowGuid + ',' + this.data.FailTypeArray[2][index[2]].RowGuid,
      FailTypeIndex: e.detail.value
    })
    console.log("complateTime", this.data.FailTypeArray[2][index[2]].ComplateTime)
    var lasttime = this.data.FailTypeArray[2][index[2]].ComplateTime.split(',')
    if (this.data.IsPublicRent == '1' || this.data.IsPublicRent == '') {
      this.setData({
        ComplateTime: '72小时'
      })
    } else if (this.data.IsPublicRent == '0') {
      this.setData({
        ComplateTime: '24小时'
      })
    }
  },

  changefail_typeColumn: function(e) {
    console.log('修改的列为', e.detail.column, '，值为', e.detail.value);
    var column = e.detail.column
    var index = e.detail.value
    switch (column) {
      case 0:
        this.setData({
          FaileTypeIndex: index,
          FaileTypeIndex1: 0
        })
        this.changeFailure()
        break;
      case 1:
        this.setData({
          FaileTypeIndex1: index
        })
        this.changeFailure()
        break;
      case 2:
        break;
    }
  },

  //故障类型联动
  changeFailure: function() {
    var that = this
    console.log("that.data.FaileTypeIndex", that.data.FaileTypeIndex)
    console.log("that.data.FaileTypeIndex1", that.data.FaileTypeIndex1)
    var failtable = that.data.table_fail
    var newArr = failtable.filter(function(item) {
      return item.ParentGuid === "0";
    });
    var newArr1 = failtable.filter(function(item) {
      return item.ParentGuid === newArr[that.data.FaileTypeIndex].RowGuid;
    });
    var newArr2 = failtable.filter(function(item) {
      return item.ParentGuid === newArr1[that.data.FaileTypeIndex1].RowGuid;
    });
    var arr = new Array();
    arr = that.data.FailTypeArray;
    arr[1] = newArr1
    arr[2] = newArr2
    that.setData({
      FailTypeArray: arr
    })
    console.log("FailTypeArray", that.data.FailTypeArray)
  },

  //获取当前空间设备
  EquipmentObtain: function(e) {
    var that = this;
    that.setData({
      EquipmentArray: [{ //报修设备集合
        RowGuid: '0',
        Name: '请选择'
      }],
    })
    if (e == 0 || e == "0" || e.length < 2) {
      return
    } else {
      var param = {
        'rowGuid': e,
      }
      wx.request({
        url: httprequest.host + httprequest.apiInfo.GetEquipmentBySpaceGuidApi,
        data: param,
        header: {
          'content-type': 'application/json' // 默认值
        },
        method: "GET",
        success(res) {
          if (res.data.equipInfo.length > 0) {
            var newArray = that.data.EquipmentArray
            for (var i = 0; i < res.data.equipInfo.length; i++) {
              newArray.push(res.data.equipInfo[i])
            }
            that.setData({
              EquipmentArray: newArray
            })
          }
        }
      })
    }
  },

  //获取当前设备Guid
  EquipmentChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      EquipmentIndex: e.detail.value,
      EquipGuid: this.data.EquipmentArray[e.detail.value].RowGuid
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

    this.setData({
      customHeight: ((app.globalData.titleBarHeight + app.globalData.statusBarHeight) * 2) + 110
    })

    focus = 0;
    // 获取完整的年月日 时分，以及默认显示的数组
    var obj = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear);
    this.setData({
      dateTimeArray: obj.dateTimeArray,
      dateTime: obj.dateTime
    });
    this.setData({
      WorkTime: this.data.dateTimeArray[0][this.data.dateTime[0]] + '-' + this.data.dateTimeArray[1][this.data.dateTime[1]] + '-' + this.data.dateTimeArray[2][this.data.dateTime[2]] + ' ' + this.data.dateTimeArray[3][this.data.dateTime[3]] + ':' + this.data.dateTimeArray[4][this.data.dateTime[4]],
      RepairTime: this.data.dateTimeArray[0][this.data.dateTime[0]] + '-' + this.data.dateTimeArray[1][this.data.dateTime[1]] + '-' + this.data.dateTimeArray[2][this.data.dateTime[2]] + ' ' + this.data.dateTimeArray[3][this.data.dateTime[3]] + ':' + this.data.dateTimeArray[4][this.data.dateTime[4]]
    })
    // console.log(wx.getStorageSync('UserInfo'))
    this.setData({
      RepairPerson: wx.getStorageSync('UserInfo').AppLogin.DisplayName,
      RepairPersonTel: wx.getStorageSync('UserInfo').AppLogin.Mobile
    })
    //获取故障类型
    this.getFailureType();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    var that = this;
    if (that.data.roomOnlyGuid == '') {
      return
    } else {
      that.EquipmentObtain(that.data.roomOnlyGuid)
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})